<template>
  <div class="buyCurriculum-container">
    <div class="list-group" ref="scrollbars">
      <van-list loading-text="加载中" v-model="loading" :finished="finished" :finished-text="listData.length > 0 ? '没有更多了' : ''" @load="initAjaxMethod">
        <div class="match-content" v-for="(item, index) in listData" :key="index"  @click="goToDetailkcgx(item,'KCGX')">
          <div class="list-header">
            <span>订单:{{item.orderid}}</span>
            <!-- <span>{{item.orderid}}</span> -->
          </div>
          <div class="demo-preview">
            <img alt="" :src="item.headerimg">
            <div class="demo-content">
            
              <div class="demo-text-user">姓名:{{item.sname}}</div>
              <div class="demo-text-phone">电话:{{item.mobile}}</div>
              <!-- demo-text demo-text-name -->
              <div class="demo-text-user">课程:{{item.t_name}}</div>
            </div>
          </div>
          <div class="list-boxs">
            <span class="time">时间:{{item.paytime | dateFrom}}</span>
            <span class="time">金额:¥<span class="list-boxs-price">{{item.price}}</span></span>
          </div>
        </div>
      </van-list>
      <empty v-if="listData.length == 0"></empty>
    </div>
    <van-popup v-model="showImg" :style="{ height: '100%',width:'100%' }">
      <div class="popup-close-header" @click="showImg=false">关闭</div>
      <div style="height: 100vh;background-color: #fff;padding:1rem 0;">
        <img :src="baseUrl+certificate" class="popup-img" alt="">
        <div class="popup-close-group">
          <div class="popup-close-button">长安保存到相册</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>
  <script>
import { PullRefresh, List, Icon, Button, Tag, Tab, Tabs, Popup } from 'vant';
import utils from "@/utils/utils";
export default {
  name: "certificate",
  components: {
    [PullRefresh.name]: PullRefresh, [List.name]: List, [Icon.name]: Icon,
    [Button.name]: Button, [Tab.name]: Tab, [Tag.name]: Tag, [Tabs.name]: Tabs, [Popup.name]: Popup
  },
  data() {
    return {
      refreshDisabled: false,
      showImg: false,
      loading: false,
      active: 0,
      finished: true,
      wxReadyOk: false,
      menuId: 3,
      baseUrl: this.$API.ASSET_IMAGES_URL,
      query: {
        pageIndex: 1,
        pageSize: 10
      },
      total: 0,
      listData: [],
      certificate: ''
    };
  },
  filters: {
    dateFrom(e) {
      if (!e) return '';
      return utils.dateFormat(e,null);
    }
  },
  mounted() {
    this.initAjaxMethod();
  },
  methods: {
    menuClick() {
      this.query.pageIndex = 1;
      this.listData = [];
      this.finished = false;
      this.loading = true;
      this.$refs['scrollbars'].scrollTop = 0;
      this.initAjaxMethod();
    },
    //列表加载
    initAjaxMethod() {
      const toast = this.$toast.loading("加载中...");
      this.$http
        .post(this.$API.GET_MEMBER_ORDER, {
          page: this.query.pageIndex,
          pageSize: this.query.pageSize
        })
        .then((res) => {
          toast.clear();
          if (res.code == 1) {
            let list = Array.isArray(res.data.list) ? res.data.list : [];
            let isOver = list.length < this.query.pageSize ? true : false;
            this.finished = isOver;
            this.loading = false;
            this.listData = this.query.pageIndex == 1 ? list : [...this.listData, ...list];
            this.total = res.data.total;
            if (!isOver) {
              this.query.pageIndex++;
            }
          }
        });
    },
    wxplayDown(id) {
      Toast.loading({ message: "加载中...", forbidClick: true });
      this.$http
        .post(this.$API.USER_RANK_CERTIFICATE, { signup_id: id })
        .then((res) => {
          Toast.clear();
          if (res.code == 1) {
            this.certificate = res.data;
            this.showImg = true;
          } else {
            this.$notify({ type: 'warning', message: res.msg });
          }
        });
    },
    wxReadyOkMethod() {
      console.log('js准备好了');
      this.wxReadyOk = true;
    },
    //保存证件号码
    wxplay(row) {
      if (!this.wxReadyOk && !this.$API.IS_DEVELOPMENT) {
        return this.$toast.fail("调起微信支付失败!");
      }
      let that = this;
      const toast = this.$toast.loading("加载中...");
      this.$http
        .post(this.$API.WX_NEWPAY, {
          tcourse_id: this.id,
          dev: this.$API.IS_DEVELOPMENT ? 1 : 0,
        },{},false)
        .then((result) => {
          console.log("详情", result);
          toast.clear();
          if (result.code == 1) {
            this.$WX.chooseWXPay({
              timestamp: result.data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
              nonceStr: result.data.nonceStr, // 支付签名随机串，不长于 32 位
              package: result.data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
              signType: result.data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
              paySign: result.data.paySign, // 支付签名
              success: function (res) {
                if (res.errMsg == "chooseWXPay:ok") {
                  that.$toast.success("支付成功");
                  that.menuClick();
                } else {
                  that.$toast.fail(res.errMsg);
                }
              },
              cancel: function (res) {
                that.$toast.fail("取消支付");
              },
            });
          } else if (result.code == 2) {
            this.$dialog.alert({
              title: "支付提示",
              message: "您的订单已支付,无需重复支付!",
            });
          } else if (result.code == 3) {
            this.$toast.success("支付成功");
            that.menuClick();
          } else {
            this.$toast.fail(result.msg);
          }
        })
        .catch((err) => {
          console.log("result.msg", err);
          toast.clear();
        });
    },
     // 课程更新跳转
     goToDetailkcgx(data,flag=1) {

        // let parme=flag==1?{course_id:data.id}:{ course_id: data.kcid,kb_id:data.id};

        this.$router.push({path:'/curriculumDetail',query:{id:data.kcid,isPlay:1}})
        if(data.lnubtype=="needpay"){
        //curriculumDetail

        }




},
  },
};
  </script>
  <style lang="less">
.buyCurriculum-container {
  height: 100%;
  padding-top: 0.2rem;
  position: relative;

  .tabs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;

    .van-tabs__wrap {
      height: 0.88rem;
    }
    .van-tab__text {
      font-size: 0.3rem;
    }
  }

  .list-group {
    height: 100%;
    padding: 0 0.2rem;
  }

  .detail-tags {
    display: flex;
    justify-content: flex-end;

    .van-tag {
      font-size: 0.24rem;
      padding: 0.1rem 0.3rem;
      border-radius: 4px;
      line-height: 0.24rem;
    }
  }

  .match-content {
    background: #fff;
    border-radius: 0.1rem;
    box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin-bottom: 0.2rem;
    font-size: 0;
    padding:0 0.2rem;
    .list-header {
      height: 0.8rem;
      line-height: 0.8rem;
      display: flex;
      justify-content: space-between;
      border-bottom:1px solid #F6FAFF;
    }
    .list-header span {
      font-size: 0.32rem;
      color:#666;
    }
    .van-col {
      height: 0.72rem;
      line-height: 0.72rem;
      font-size: 0.28rem;
      text-align: center;
    }
    .demo-preview {
      display: flex;
      padding: 0.2rem 0;
      background: #fff;
      border-bottom: 1px solid #F6FAFF;
    }
    .demo-preview img {
      flex-shrink: 0;
      width: 0.8rem;
      height: 0.8rem;
      margin-right: 0.32rem;
      background: #eee;
      border-radius: 50%;
    }
    .demo-text-name{
      font-size: 0.3rem;
      color:#333;
    }
    .demo-text-user{
      font-size: 0.26rem;
      color:#666;
      padding-top:0.15rem;
    }
    .demo-text-phone{
      font-size: 0.26rem;
      color:#666;
      padding-top:0.15rem;
    }
    .list-boxs {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 0.8rem;
      line-height: 0.8rem;
    }
    .list-boxs .time {
      font-size: 0.28rem;
      color: #666;
    }
  }

  .list-boxs-price{
      font-size: 0.32rem;
      //color: #ff6857 ;
      // font-weight: bold;
    }

  .bottom-button {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-top: 0.2rem;
  }

  .popup-close-group {
    padding: 0.1rem 24%;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
  }
  .popup-close-button {
    height: 0.7rem;
    color: #333;
    line-height: 0.7rem;
    text-align: center;
    font-size: 0.28rem;
  }
  .popup-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .popup-close-header {
    font-size: 0.3rem;
    position: absolute;
    top: 0;
    left: 0;
    padding: 0 0.3rem;
    text-align: right;
    height: 1rem;
    line-height: 1rem;
    width: 100%;
  }
}
</style>